{% extends 'base.html' %}

{% block title %}我的借阅{% endblock %}

{% block content %}
<h2>我的借阅</h2>
{% if records %}
<table class="table table-striped">
    <thead>
        <tr>
            <th>图书</th>
            <th>借阅日期</th>
            <th>应还日期</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        {% for record in records %}
        <tr>
            <td><a href="{% url 'books:book_detail' record.book.pk %}">{{ record.book.title }}</a></td>
            <td>{{ record.borrow_date }}</td>
            <td>{{ record.due_date }}</td>
            <td>
                {% if record.is_returned %}
                <span class="badge bg-success">已归还</span>
                {% else %}
                <span class="badge bg-{% if record.due_date < today %}danger{% else %}primary{% endif %}">
                    {% if record.due_date < today %}逾期{% else %}借阅中{% endif %}
                </span>
                {% endif %}
            </td>
            <td>
                {% if not record.is_returned %}
                <a href="{% url 'books:return_book' record.book.pk %}" class="btn btn-sm btn-warning">归还</a>
                {% endif %}
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% else %}
<div class="alert alert-info">您当前没有借阅任何图书</div>
{% endif %}
{% endblock %}